#include <stdio.h>
#include <stdlib.h>

typedef struct BNode
{
    BNode *lchild;
    BNode *rchild;
    int data;
} BNode, *BTree;

// 二叉树左小于右
void ALgo(BTree &T)
{
    if (!T)
    {
        return;
    }
    if (T->lchild && T->rchild)
    {
        if (T->lchild->data > T->rchild->data)
        {
            BTree temp = T->lchild;
            T->lchild = T->rchild;
            T->rchild = temp;
        }
    }
    ALgo(T->lchild);
    ALgo(T->rchild);
}

// 测试
void print(BTree T)
{
    if (T)
    {
        printf("%d ", T->data);
        print(T->lchild);
        print(T->rchild);
    }
}

BNode *GetNode(int x)
{
    BNode *node = (BNode *)malloc(sizeof(BNode));
    node->data = x;
    node->lchild = NULL;
    node->rchild = NULL;
}

/***
 *          1
 *      3       2
 *   4        6    5
 * */

/***
 *          1
 *      2       3
 *   5    6   4      
 * */
int main()
{
    BTree T = GetNode(1);
    T->lchild = GetNode(3);
    T->rchild = GetNode(2);
    T->lchild->lchild = GetNode(4);
    T->rchild->rchild = GetNode(5);
    T->rchild->lchild = GetNode(6);
    print(T);
    ALgo(T);
    printf("\n");
    print(T);
    return 0;
}
